package com.ning.weixin.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

import com.ning.weixin.entity.AcLocation;

/**
 * @author MENG_LI_DONG
 * @version 2018年12月18日 下午9:27:56
 */
@Component
public class AcLocationDao {
	@Autowired
	private JdbcTemplate jdbcTemplate;
	public AcLocation getByFlag(String flag){
		String sql = "select t.* from ac_location t where t.flag = ?";
		try {
			return jdbcTemplate.queryForObject(sql, new String[]{flag}, new RowMapper<AcLocation>(){
				@Override
				public AcLocation mapRow(ResultSet rs, int row)
						throws SQLException {
					AcLocation t = new AcLocation();
					Timestamp createTime = rs.getTimestamp("create_time");
					if(createTime!=null){
						t.setCreateTime(new Date(createTime.getTime()));
					}
					t.setFlag(rs.getString("flag"));
					t.setId(rs.getLong("id"));
					t.setIsDeleted(rs.getInt("is_deleted"));
					t.setName(rs.getString("name"));
					t.setThumb(rs.getString("thumb"));
					Timestamp updateTime = rs.getTimestamp("update_time");
					if(updateTime!=null){
						t.setUpdateTime(new Date(updateTime.getTime()));
					}
					return t;
				}
			});
		} catch(Exception e) {
			return null;
		}
	}
}
